//
//  ClassTimeViewController.m
//  jiyujiaProgram
//
//  Created by 中良 赵 on 15/12/8.
//  Copyright © 2015年 中良 赵. All rights reserved.
//

#import "ClassTimeViewController.h"
#import "UWDatePickerView.h"


@interface ClassTimeViewController ()
{
    UWDatePickerView *_pickerView;
    NSString *  startTime;
    NSString *  endTime;

}
@end

@implementation ClassTimeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    startTime=@"";
    endTime=@"";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 66.f;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
            [self setupDateView:DateTypeOfStart];
        }
            break;
        case 1:
        {
            [self setupDateView:DateTypeOfEnd];
            
        }
            break;
            
        default:
            break;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
    
    switch (indexPath.row) {
        case 0:
        {
            cell.textLabel.text=[NSString stringWithFormat:@"开始时间:  %@",startTime];
        }
            break;
        case 1:
        {
            cell.textLabel.text=[NSString stringWithFormat:@"结束时间:  %@",endTime];
            
        }
            break;
            
        default:
            break;
    }
    return cell;

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)setupDateView:(DateType)type {
    
    _pickerView = [UWDatePickerView instanceDatePickerView];
    _pickerView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    [_pickerView setBackgroundColor:[UIColor lightGrayColor]];
    _pickerView.delegate = self;
    _pickerView.type = type;
    [self.view addSubview:_pickerView];
    
}

- (void)getSelectDate:(NSString *)date type:(DateType)type {
    
    NSLog(@"时间 : %@",date);
    switch (type) {
        case DateTypeOfStart:
            // TODO 日期确定选择
            startTime=date;
            break;
            
        case DateTypeOfEnd:
            // TODO 日期取消选择
            endTime=date;
            break;
        default:
            break;
    }
    [_tableview reloadData];
}


- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)confirmAction:(id)sender {
    if ([endTime length]&&[startTime length]) {
        NSDictionary *dict =[[NSDictionary alloc] initWithObjectsAndKeys:[NSString stringWithFormat:@"%@/%@",startTime,endTime],@"time", nil];
        //创建通知
        NSNotification *notification =[NSNotification notificationWithName:@"postStringToUp" object:nil userInfo:dict];
        //通过通知中心发送通知
        [[NSNotificationCenter defaultCenter] postNotification:notification];
        [self.navigationController popViewControllerAnimated:YES];
    }
}
@end
